package com.xinhua.erp.utils;

import java.text.DecimalFormat;
import java.text.Format;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class OrderNumber {

    private static LocalDateTime localDateTime=LocalDateTime.now();

    private static int mantissa=0;

    private static int sk=0;  //收款

    private static int fk=0;   //付款

    private static int account=0;   //账户

    private static int ls=0;   //零售

    private static int xs=0;   //销售


    /**
     * 获取现在时间
     * @return
     */
    public static LocalDateTime getLocalDateTime() {
        return localDateTime;
    }

    public static void setLocalDateTime(LocalDateTime localDateTime) {
        OrderNumber.localDateTime = localDateTime;
    }

    public static void setOrderNumber(int mantissa) {

        OrderNumber.mantissa = mantissa;

    }

    public static String getOrderNumber() {
        if (LocalDateTime.now().getDayOfYear()!=localDateTime.getDayOfYear()){
            setOrderNumber(0);
            localDateTime=LocalDateTime.now();
        }


        mantissa=mantissa+1;
        Format test = new DecimalFormat("000");

        String afterThree = test.format(mantissa);

        LocalDateTime now = LocalDateTime.now();

        String format = now.format(DateTimeFormatter.BASIC_ISO_DATE);

        String number = format+afterThree;

        return number;
    }

    public static String getSkNumber() {

        if (LocalDateTime.now().getDayOfYear()!=localDateTime.getDayOfYear()){
            setSk(0);
            localDateTime=LocalDateTime.now();
        }


        sk=sk+1;
        Format format = new DecimalFormat("000");

        String afterThree = format.format(sk);

        String format1 = localDateTime.format(DateTimeFormatter.BASIC_ISO_DATE);

        String orderNumber = "SK"+format1+afterThree;
        return orderNumber;
    }

    public static void setSk(int sk) {
        OrderNumber.sk = sk;
    }

    public static String getFkNumber() {
        if (LocalDateTime.now().getDayOfYear()!=localDateTime.getDayOfYear()){
            setFk(0);
            localDateTime=LocalDateTime.now();
        }


        fk=fk+1;
        Format format = new DecimalFormat("000");

        String afterThree = format.format(fk);

        String format1 = localDateTime.format(DateTimeFormatter.BASIC_ISO_DATE);

        String orderNumber = "FK"+format1+afterThree;
        return orderNumber;
    }

    public static void setFk(int fk) {
        OrderNumber.fk = fk;
    }

    public static String getAccount() {
        if (LocalDateTime.now().getDayOfYear()!=localDateTime.getDayOfYear()){
            setAccount(0);
            localDateTime=LocalDateTime.now();
        }
        account=account+1;
        Format format = new DecimalFormat("000");

        String afterThree = format.format(account);

        String format1 = localDateTime.format(DateTimeFormatter.BASIC_ISO_DATE);

        String orderNumber = "AC"+format1+afterThree;
        return orderNumber;
    }

    public static void setAccount(int account) {
        OrderNumber.account = account;
    }

    public static String getLs() {
        if (LocalDateTime.now().getDayOfYear()!=localDateTime.getDayOfYear()){
            setLs(0);
            localDateTime=LocalDateTime.now();
        }
        ls=ls+1;
        Format format = new DecimalFormat("000");

        String afterThree = format.format(ls);

        String format1 = localDateTime.format(DateTimeFormatter.BASIC_ISO_DATE);

        String orderNumber = "LS"+format1+afterThree;
        return orderNumber;
    }

    public static void setLs(int ls) {
        OrderNumber.ls = ls;
    }

    public static String getXs() {
        if (LocalDateTime.now().getDayOfYear()!=localDateTime.getDayOfYear()){
            setXs(0);
            localDateTime=LocalDateTime.now();
        }
        xs=xs+1;
        Format format = new DecimalFormat("000");

        String afterThree = format.format(xs);

        String format1 = localDateTime.format(DateTimeFormatter.BASIC_ISO_DATE);

        String orderNumber = "XS"+format1+afterThree;
        return orderNumber;
    }

    public static void setXs(int xs) {
        OrderNumber.xs = xs;
    }
}
